<?php

class BPTable
{
    private $name;
    private $fields;

    public function getName() {return $this->name;}
    public function setName($name) {$this->name = $name;}

    public function getFields() {return $this->fields;}
    public function addField($field) {$this->fields[] = $field;}

}

class BPElement
{
    private $fields;
    private $values;

    public function __construct($fields, $values)
    {
        $this->fields = $fields;
        $this->values = $values;
    }

    public function buildElement()
    {
        $string = '<element';
        foreach($this->fields as $field)
        {
            $string .= ' ' . $field .'="' . ($this->values[$field] ? $this->values[$field] : "") . '"';
        }
        $string .= ' />';
        return $string;
    }
}

class BPSection
{
    private $name;
    private $elements;

    public function __construct($name)
    {
        $this->name = $name;
        $this->elements = array();
    }

    public function insertElement($fields, $values)
    {
        $this->elements[] = new BPXMLElement($fields, $values);
    }

    public function insertBPElement($element)
    {
        $this->elements[] = $element;
    }

    public function getSection()
    {
        $string = '<section name="' . $this->name . '" >'. PHP_EOL;
        foreach($this->elements as $element)
        {
            $string .= $element->buildElement() . '' . PHP_EOL;
        }
        $string .= "</section>";
        return $string;
    }
}




